import { h } from 'vue'
import { service } from '../../../utils/request'

const url = '/geological_data_mgr/resourcefile'
export default class ResourceFile {
  constructor() {
    
  }
  pageObj(data:any){
    return service({
      url: `${url}/pageObj`,
      method: 'post',
      data
    })
  }
  count4Page(data:any){
    return service({
      url: `${url}/count4Page`,
      method: 'post',
      data
    })
  }
  createObj(data:any):any{
    return service({
      url: `${url}/createObj`,
      method: 'post',
      data: this.format(data)
    })
  }
  getObjById(data:any):any{
    return service({
      url: `${url}/getObjById`,
      method: 'post',
      data
    })
  }

  updateObj(data:any):any{
    return service({
      url: `${url}/updateObj`,
      method: 'post',
      data: this.format(data)
    })
  }

  listObj(data:any):any{
    return service({
      url: `${url}/listObj`,
      method: 'post',
      data
    })
  }

  deleteObj(data:any):any{
  	const ID = this.getKey(data)
    return service({
      url: `${url}/deleteObj`,
      method: 'post',
      data: { ID }
    })
  }

  deleteObjs(data:any):any{
    return service({
      url: `${url}/deleteObjs`,
      method: 'post',
      data
    })
  }

  getDesc(obj:any) :any{
    return obj.Name
  }
  getKey(obj:any) :any{
  	return ""+obj.Token
  }
  getDescField() :any{
    return 'Name'
  }
  getKeyField(obj:any) :any{
    return ["Token"]
  }
  format(obj:any) :any{
	 if(null !== obj.Checked && undefined !== obj.Checked) {
		obj.Checked = parseFloat(""+obj.Checked)
	 }
     return obj
  }
  format4Select(obj:any):any {	
    return obj
  }
  // 字段的名称
  fields = [
    {
      title: '名称',
      dataIndex: 'Name',
      key: 'resource_file.name',
      query: false,
      sorter: true
    },
    {
      title: '已校验',
      dataIndex: 'Checked',
      key: 'resource_file.checked',
      render: (t, itemData, item) => {
        switch (itemData) {
          case 0 : return h('span',{},'未校对')
          case 1 : return h('span',{},'已校对')
        }
      },
      query: true,
      sorter: true
    },
    {
      title: '类型',
      dataIndex: 'FileType',
      key: 'resource_file.file_type',
      render: (t, itemData, item) => {
        switch (itemData) {
          case 'pdf' : return h('span',{},'pdf')
          case 'txt' : return h('span',{},'纯文本')
          case 'epub' : return h('span',{},'epub格式')
          case 'md' : return h('span',{},'markdown格式')
          case 'else' : return h('span',{},'其他')
        }
      },
      query: false,
      sorter: true
    },
    {
      title: '内容',
      dataIndex: 'Content',
      key: 'resource_file.content',
      query: true,
      sorter: true,
      hide: true
    },
    {
      title: 'ai检测报告',
      dataIndex: 'AiReport',
      key: 'resource_file.ai_report',
      query: true,
      sorter: true,
      hide: true
    },
    {
      title: '原始文件',
      dataIndex: 'RawFile',
      key: 'resource_file.raw_file',
      query: false,
      sorter: true,
      hide: true
    },
    {
      title: '备注',
      dataIndex: 'Nt',
      key: 'resource_file.nt',
      query: true,
      sorter: true
    }
  ]
}
